<?php
/*******************************************************************************
 * $Date:: May 30, 2011 10:01:46 AM                                             $
 * $Revision:                                                                  $
 * $Author:: Tuan Duong                                                        $
 * $Comment::                                                                  $
 ******************************************************************************/ 

/**
 * Plugin for loading layout of the modules
 *
 * @author	Tuan Duong <duongthaso[at]gmail[dot]com>
 * @version 
 */

class Sss_Controller_Plugin_LayoutLoader
    extends Zend_Controller_plugin_Abstract
{
    public function preDispatch(Zend_Controller_Request_Abstract $request)
    {
        $config     = Zend_Controller_Front::getInstance()
                            ->getParam('bootstrap')->getOptions();
        $moduleName = $request->getModuleName();
 
        if (isset($config[$moduleName]['resources']['layout']['layout'])) {
            $layoutScript = $config[$moduleName]['resources']['layout']['layout'];
            Zend_Layout::getMvcInstance()->setLayout($layoutScript);
        }
 
        if (isset($config[$moduleName]['resources']['layout']['layoutPath'])) {
            $layoutPath = $config[$moduleName]['resources']['layout']['layoutPath'];
            Zend_Layout::getMvcInstance()->setLayoutPath($layoutPath);
        }
    }
}